﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Common
{
    public class UICookie
    {
        public static void AddCookie(string name, string value)
        {

            HttpCookie cookie = new HttpCookie(name, HttpUtility.UrlEncode(value));
            cookie.Expires = DateTime.Now.AddHours(2);
            HttpContext.Current.Response.Cookies.Add(cookie);//将cookie写入客户端
        }
        public static string ReadCookie(string Key)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[Key];
            if (null == cookie)
            {
                return string.Empty;
            }
            else
            {
                //找到指定的cookie，显示cookie的值
                return cookie.Value.ToString();

            }
        }
        public static void removeCookie(string name)
        {
            HttpContext.Current.Response.Cookies[name].Expires = DateTime.Now;//cookie将马上过期        
        }
    }
}